﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class MessagePopup : MonoBehaviour
{
    public Text text;
    public RectTransform hidePos;
    public RectTransform showPos;
    RectTransform rect;
    //public GameObject back;
    public GameObject yes;
    public GameObject no;
    public GameObject confirm;

    public Text numHint;
    public Text numRandom;
    public Text numCoin;

    public GameObject store;
    public GameObject video;
    public GameObject btn_money;
    //public GameObject rubyInfo;

    void OnEnable()
    {
    }

    void Start()
    {
        rect = GetComponent<RectTransform>();
    }
    public void showPopup(int mode)
    {
        _moveUp();
        no.SetActive(true);


        transform.Find("EndlessMode").gameObject.SetActive(mode > 2);
        transform.Find("NormalMode").gameObject.SetActive(mode <= 2);
        
            //transform.Find("EndlessMode/text").gameObject.SetActive(false);
        
        GameStatic.coin_need_to_recover = GameStatic.getCoinNeedToRecover();
        //back.SetActive (true);
        //rubyInfo.SetActive (true);
    }
    public void showPopup(string mes)
    {
        _moveUp();
        text.text = mes;
        //back.SetActive (true);
        no.SetActive(false);
        yes.SetActive(false);
        confirm.SetActive(true);
    }
    public void showYesNo(string mes)
    {
        _moveUp();
        text.text = mes;
        //back.SetActive (true);
        no.SetActive(true);
        //yes.SetActive (true);
        confirm.SetActive(false);
    }
    void _moveUp()
    {
        transform.parent.gameObject.SetActive(true);
        GetComponent<Animator>().Play("showpause");
        //iTween.ValueTo(gameObject, iTween.Hash(
        //	"from", hidePos.anchoredPosition,
        //	"to", showPos.anchoredPosition,
        //	"time", 0.2f,
        //	"onupdatetarget", this.gameObject, 
        //	"onupdate", "MoveGuiElement"));
    }
    public void MoveGuiElement(Vector2 position)
    {
        rect.anchoredPosition3D = position;
    }
    public void hidePopup()
    {
        Invoke("hideParent", 0.2f);
        GetComponent<Animator>().Play("hidepause");
        //iTween.ValueTo(gameObject, iTween.Hash(
        //	"from", showPos.anchoredPosition,
        //	"to", hidePos.anchoredPosition,
        //	"time", 0.2f,
        //	"onupdatetarget", this.gameObject, 
        //	"onupdate", "MoveGuiElement"));
        //if (back != null) {
        //	back.SetActive (false);	
        //}
        //      if (rubyInfo != null) {
        //	rubyInfo.SetActive (false);
        //}
    }

    void hideParent()
    {
        transform.parent.gameObject.SetActive(false);
    }
    public void RubyToHint()
    {
        int ruby = Save.getPlayerCoin();
        if (ruby >= 100)
        {
            ItemController.addHintItem(10);
            Save.addPlayerCoin(-100);
        }
        else
        {
        }
    }

    public void RubyToRandom()
    {
        int ruby = Save.getPlayerCoin();
        if (ruby >= 100)
        {
            ItemController.addRandomItem(10);
            Save.addPlayerCoin(-100);
        }
        else
        {
        }
    }

    public void RubyToResurenge()
    {
        int ruby = Save.getPlayerCoin();
        if (ruby >= 50)
        {
            GameObject.FindObjectOfType<LogicLevel>().setLevel(GameStatic.currentLevel);
            Map.ins.isGameOver = false;
            hidePopup();
            Save.addPlayerCoin(-50);
        }
        else
        {
        }
    }

    public void VideoToResurenge()
    {
    }
}
